<?php

namespace app\models\db;

use Yii;

/**
 * This is the model class for table "t_favourite".
 *
 * @property string $id
 * @property string $good_id
 * @property string $mini_programs_id
 * @property string $create_datetime
 * @property string $user_id
 *
 * @property Goods $good
 * @property MiniPrograms $miniPrograms
 * @property TUser $user
 */
class Favourite extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 't_favourite';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id'], 'required'],
            [['create_datetime'], 'safe'],
            [['id', 'good_id', 'mini_programs_id', 'user_id'], 'string', 'max' => 36],
            [['good_id'], 'exist', 'skipOnError' => true, 'targetClass' => Goods::className(), 'targetAttribute' => ['good_id' => 'id']],
            [['mini_programs_id'], 'exist', 'skipOnError' => true, 'targetClass' => MiniPrograms::className(), 'targetAttribute' => ['mini_programs_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => TUser::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'good_id' => 'Good ID',
            'mini_programs_id' => 'Mini Programs ID',
            'create_datetime' => 'Create Datetime',
            'user_id' => 'User ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGood()
    {
        return $this->hasOne(Goods::className(), ['id' => 'good_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMiniPrograms()
    {
        return $this->hasOne(MiniPrograms::className(), ['id' => 'mini_programs_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(TUser::className(), ['id' => 'user_id']);
    }
}
